package com.edu.exam.entity.curriculum.questionbank;

import com.edu.exam.enums.questionbank.QuestionTagCategory;
import com.edu.exam.enums.questionbank.QuestionTagType;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.time.LocalDateTime;

/**
 * 试题标签实体类
 * 对应数据库表：question_tags
 *
 * 管理试题的标签信息，包括标签名称、类型、颜色等。
 * 支持标签的创建、查询、更新和状态管理。
 * 关联试题、知识点等关键信息，提供试题标签的完整视图。
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Comment("试题标签表")
@SQLDelete(sql = "UPDATE question_tags SET is_deleted = true, delete_time = CURRENT_TIMESTAMP WHERE id = ?")
@Where(clause = "is_deleted = false")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class QuestionTag {

    /**
     * 标签唯一标识符
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 试题ID
     */
    @NotNull(message = "试题ID不能为空")
    @Column(name = "question_id", nullable = false)
    private Long questionId;

    /**
     * 标签名称
     */
    @NotBlank(message = "标签名称不能为空")
    @Size(max = 100, message = "标签名称长度不能超过100个字符")
    @Column(name = "tag_name", nullable = false, length = 100)
    private String tagName;

    /**
     * 标签代码
     */
    @Size(max = 50, message = "标签代码长度不能超过50个字符")
    @Column(name = "tag_code", length = 50)
    private String tagCode;

    /**
     * 标签类型
     */
    @NotNull(message = "标签类型不能为空")
    @Enumerated(EnumType.STRING)
    @Column(name = "tag_type", nullable = false, length = 20)
    private QuestionTagType tagType;

    /**
     * 标签分类
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "tag_category", length = 20)
    private QuestionTagCategory tagCategory;

    /**
     * 标签描述
     */
    @Size(max = 500, message = "标签描述长度不能超过500个字符")
    @Column(name = "description", length = 500)
    private String description;

    /**
     * 标签颜色
     */
    @Size(max = 20, message = "标签颜色长度不能超过20个字符")
    @Column(name = "tag_color", length = 20)
    private String tagColor;

    /**
     * 标签图标
     */
    @Size(max = 50, message = "标签图标长度不能超过50个字符")
    @Column(name = "tag_icon", length = 50)
    private String tagIcon;

    /**
     * 标签权重
     */
    @Column(name = "tag_weight")
    @Builder.Default
    private Integer tagWeight = 0;

    /**
     * 是否系统标签
     */
    @Column(name = "is_system")
    @Builder.Default
    private Boolean isSystem = false;

    /**
     * 是否激活
     */
    @Column(name = "is_active")
    @Builder.Default
    private Boolean isActive = true;

    /**
     * 使用次数
     */
    @Column(name = "usage_count")
    @Builder.Default
    private Integer usageCount = 0;

    /**
     * 关联的知识点ID列表，JSON格式
     */
    @Column(name = "knowledge_points", columnDefinition = "TEXT")
    private String knowledgePoints;

    /**
     * 记录创建时间
     */
    @Column(name = "created_time", nullable = false, updatable = false)
    private LocalDateTime createdTime;

    /**
     * 记录最后更新时间
     */
    @Column(name = "updated_time", nullable = false)
    private LocalDateTime updatedTime;

    /**
     * 创建人用户ID
     */
    @Size(max = 50, message = "创建人长度不能超过50个字符")
    @Column(name = "created_by", nullable = false, length = 50)
    private String createdBy;

    /**
     * 最后更新人用户ID
     */
    @Size(max = 50, message = "更新人长度不能超过50个字符")
    @Column(name = "updated_by", length = 50)
    private String updatedBy;

    /**
     * 乐观锁版本号
     */
    @Version
    @Column(name = "version", nullable = false)
    @Builder.Default
    private Integer version = 1;

    /**
     * 软删除标记
     */
    @Column(name = "is_deleted", nullable = false)
    @Builder.Default
    private Boolean isDeleted = false;

    /**
     * 删除时间
     */
    @Column(name = "delete_time")
    private LocalDateTime deleteTime;
}